define(['app'], function(app) {
    'use strict';
    //实例化方法
    var factory = function (Http) {
        /**
         * 一键切换数据获取方式
         * @param {Object} result
         */
        function get_data_detail(result) {
            if (false) {
                result = '{"success":true,"msg":"","result":{"act_id":"001","name":"促销","abstract":"哈啊啊啊啊，你是来秀逗的吗","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","apply_end_time":"2017/01/31 09:00:00","word":{"id":"001","word":"问卷001"},"brand_id":"001","brand_name":"博世","cat_type_id":"001","cat_type_name":"电动工具","group_id":"12345897"},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            }
            else {
                return result;
            }
        };
        //获取中奖名单
        function get_winner_list(result) {
            if (false) {
                result = '{"success":true,"msg":"","result":{"act_id":"001","list":[{"member_name":"张三","region":"上海-上海市-宝山区"},{"member_name":"李四","region":"上海-上海市-静安区"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            }
            else {
                return result;
            }
        };
        
		//返回信息
		return {
			//测试活动详情
			detail: function(act_id, callback) {
				Http.post({
					method: 'goods.test.detail',
					act_id: act_id
				}, function(result) {
					//请求成功
					if(callback) {
						callback(get_data_detail(result).result,result.process_time);
					}
				}, function(e) {
					//请求异常
				}, function() {
					//请求完成，一般不做什么事情
				});
			},
			//中奖名单 
			winninglist: function(act_id,callback) {
				Http.post({
					method: 'goods.test.winninglist',
					act_id: act_id
				}, function(result) {
					//请求成功
					if(callback) {
						callback(get_winner_list(result).result);
					}
				}, function(e) {
					//请求异常
				}, function() {
					//请求完成，一般不做什么事情
				});
			},
			//申请参加新品测试活动
			apply: function(act_id, callback) {
				Http.post({
					method: 'goods.test.apply',
					act_id: act_id
					// word_id: word_id
				}, function(result) {
					//请求成功
					if(callback) 
						callback(result);
				}, function(e) {
					//请求异常
				}, function() {
					//请求完成，一般不做什么事情
				});
			}
			
			
		};
	}
	factory.$inject = ['Http'];
	return app.registerService("Newproductpost_test", factory);
});